// pages/templates/couponli/couponli.js
import Router from '../../../utils/router.js';
import base from '../../../config/base.js';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item: {
      type: Object,
      value:{}
    },
    index: {
      type: String,
      value: {}
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    coupon_bk: base.static + '/my/coupon_bk2.png',
    coupon_ky: base.static + '/my/coupon_ky2.png',
    shixiao: base.static + '/my/shixiao.png',
    yshiyong: base.static + '/my/yshiyong.png',
    ylingqu: base.static + '/my/ylingqu.png',
    gx_coupon: base.static + '/my/checks.png', 
  },
  ready(){
    // console.log()
    // let item = this.properties.item;
    // let ch = this.dateAmu(item.current_time) - this.dateAmu(item.period_validity_e);
    // console.log(item)
    // if (item.scene == 'pay') {
    //   var price = Number(item.full)-Number(item.price_all);
    //   console.log(price)
    //   if (ch <= 0 && item.is_use == 0 &&price<=0) {
    //     item.status = 1;
    //   } else if (ch > 0 || item.is_use == 1 || price>0) {
    //     item.status = 0;
    //   }
    // }else{
    //   if (ch <= 0 && item.is_use == 0) {
    //     item.status = 1;

    //   } else if (ch > 0 || item.is_use == 1) {
    //     item.status = 0;
    //   }
    // }
    
    // this.setData({
    //   item
    // });
  },
  /**
   * 组件的方法列表
   */
  methods: {
    gostore() {
      let item = this.data.item;
      let store_id = wx.getStorageSync('user_info').lastView.seid; 
      if (item.scene != "pay" && item.status == 1 && item.type == "not_use" && item.goods_id == 0)  {
        Router.go('store', '', `reLaunch`);
      } else if (item.goods_id != 0 && item.type == "not_use"){
        Router.go('detail', `goods_id=${item.goods_id}&store_id=${store_id}`);        
      }
    },
    selectfn(){
      let item = this.data.item,
        index = this.data.index;
      if(item.status==0){
        return false
      }
      if (item.active == 1){
        // item.active = 0;
      } else if (item.active == 0){
        item.active = 1
      }
      this.setData({
        item,
        index
      });
      var myEventDetail = {
        item,
        index
      } // detail对象，提供给事件监听函数
      var myEventOption = {} // 触发事件的选项
      this.triggerEvent('selectCoupon', myEventDetail, myEventOption)
    },
    dateAmu(date) {
      var c = '';
      if(date){
        if (date && date.indexOf('-') > -1) {
          date = date.replace(/\-/g, "/");
          var d = (date && new Date(date)) ? new Date(date) : new Date(); 
          c = d.getTime();
        }
      }
      return c;
    },  
  }
})
